﻿using System;
using System.Collections.Generic;

namespace wires_as_objects
{
    class ToDictionary : Board
    {
        public ToDictionary(Split_config_into_parameters split_params,
                            Split_parameters_into_key_and_value split_kv,
                            Assemble_dictionary assemble)
        {
            var wProcess = CreateWire<string>();
            _process = wProcess.Process;
            wProcess.Result += split_params.Process;

            var w0 = CreateWire<IEnumerable<string>>();
            split_params.Result += w0.Process;
            w0.Result += split_kv.Process;

            var w1 = CreateWire<IEnumerable<KeyValuePair<string, string>>>();
            split_kv.Result += w1.Process;
            w1.Result += assemble.Process;

            var wEnd = CreateWire<Dictionary<string, string>>();
            assemble.Result += wEnd.Process;
            wEnd.Result += x => this.Result(x);
        }

        private Action<string> _process;
        public void Process(string configuration) { _process(configuration); }

        public event Action<Dictionary<string,string>> Result;
    }
}